package com.example.demo.producer;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class MyProducer {

    public static void main(String[] args) {

        Properties properties = new Properties();

        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.1.1");

        properties.put("acks","all");

        properties.put("retires",3); // 重试次数

        properties.put("linger.ms",1) ; // 等待时间

        properties.put("batch.size",16348) ; // 发送批次的大小

        properties.put("buffer.memory",33554432) ; //缓冲区大小

        properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerialization");

        properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerialization");

        KafkaProducer<String, String> producer = new KafkaProducer<>(properties);


        for (int i =0 ;i < 10 ;i++){
            producer.send(new ProducerRecord<>("first","cwy--"+i));
        }

        producer.close();
    }
}
